#include "gotorowdialog.h"
#include "ui_gotorowdialog.h"
#include <QRegExpValidator>
#include <QDebug>
#include <QMessageBox>

GotoRowDialog::GotoRowDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::GotoRowDialog)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    ui->goToRowLineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));
    ui->goToRowLineEdit->setPlaceholderText(tr("你只能在此处键入数字。"));
    connect(ui->goToRowLineEdit,&QLineEdit::textChanged,this,&GotoRowDialog::setBtnEnable);
}

GotoRowDialog::~GotoRowDialog()
{
    delete ui;
}

void GotoRowDialog::on_closeBtn_clicked()
{
    this->close();
}

void GotoRowDialog::on_cancelBtn_clicked()
{
    this->close();
}



void GotoRowDialog::on_gotoRowBtn_clicked()
{
    int targetRow = ui->goToRowLineEdit->text().toInt();
    if(ui->goToRowLineEdit->text().isEmpty())
    {
        QMessageBox::information(this,"HanL的记事本-跳行","跳转行号为空",QMessageBox::Ok);
        return;
    }else if(targetRow <= 0 )
    {
        QMessageBox::information(this,"HanL的记事本-跳行","行数超过了总行数",QMessageBox::Ok);
        return;
    }

    emit goToTargetRow(targetRow);
    this->close();
}

void GotoRowDialog::setBtnEnable()
{
    ui->gotoRowBtn->setEnabled(!ui->goToRowLineEdit->text().isEmpty());
}
